import React, { useEffect, useState } from "react";
import { connect } from "react-redux";
import { setInterval } from "timers/promises";
import action from "../../../store/Actions";
import { importsExcel, exportExcel } from "../../../utils/excel";
function Statistics(props) {
  const asyncFunction = (callback, ms) => {
    setTimeout(() => {
      callback();
    }, ms);
  };
  asyncFunction(() => {
    const { MenuList } = props.homeReducer;
    function transArr(node) {
      let queue = [node];
      let data = []; //返回的数组结构
      while (queue.length !== 0) {
        //当队列为空时就跳出循环
        let item = queue.shift(); //取出队列中第一个元素
        data.push({
          id: item.id,
          parentId: item.college,
          name: item.stage,
        });
        let children = item.children; // 取出该节点的孩子
        if (children) {
          for (let i = 0; i < children.length; i++) {
            queue.push(children[i]); //将子节点加入到队列尾部
          }
        }
      }
      return data;
    }
    console.log(transArr(MenuList));
  }, 1000);
  useEffect(() => {
    const { getMenuList } = props;
    getMenuList();
  }, []);

  return (
    <div className="Statistics">
      <input
        type="file"
        accept=".xls,.xlsx"
        onChange={(e) => {
          importsExcel(e).then((res) => {
            console.log(res);
          });
        }}
      />
    </div>
  );
}
export default connect((state) => state, action.homeActions)(Statistics);
